package com.zhkj.txg.module.group.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.zhkj.lib.base.BaseViewModel
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.HttpResponse
import com.zhkj.lib.http.ViewModelSubscribeListener
import com.zhkj.lib.utils.AccountManager
import com.zhkj.txg.module.group.model.GroupManager
import com.zhkj.txg.module.product.entity.ProductResponse

class GroupDetailViewModel(application: Application) : BaseViewModel(application) {
    private val groupManager = GroupManager()
    val productLiveData = MutableLiveData<HttpResponse<ProductResponse>>()
    val collectProductLiveData = MutableLiveData<HttpResponse<BaseResponse>>()

    /**
     * 获取产品数据
     */
    fun getProduct(id: String, shareId: Int = 0) {
        val token = AccountManager.getToken()
        val listener = ViewModelSubscribeListener(productLiveData)
        val product = groupManager.getProduct(token, id, shareId, listener)
        dispose.add(product)
    }


    /**
     * 收藏/取消收藏商品
     */
    fun collectGoods(
        token: String, goodsId: Long
    ) {
        val listener = ViewModelSubscribeListener(collectProductLiveData)
        val collectProduct = groupManager.collectProduct(token, goodsId, listener)
        dispose.add(collectProduct)
    }
}